﻿#ifndef COMMAND_H
#define COMMAND_H
#include <QObject>
#include <QMutexLocker>

enum ARVCMDTYPE{
    type_incab,
    type_outcab
};

enum ARVCMDFACE{
    face_a,
    face_b
};

class ArvCommand
{
public:
    static ArvCommand& getInstance() {
        static ArvCommand instance;
        return instance;
    }
public:
    int32_t PortLocation_X; //出货口X
    int32_t PortLocation_Y; //出货口Y
    int32_t StorgeLocation_X;   //货位X
    int32_t StorgeLocation_Y;   //货位Y
    uint8_t Type; //true-存 false-取
    uint8_t Face; //货位在A面还是B面  true-A  false-B
    bool HaveNext;  //是否有下一条指令
    bool isExCompleted = true;  //动作是否完成
    int8_t StepCnt; //调试状态下步骤状态
    bool isDebug;   //是否分步调试指令
    QString QRCode; //二维码
    QString CmdCode;

    // 重载 == 运算符 判断两条指令的内容是否相同
    bool operator==(const ArvCommand& other) const {
        if(PortLocation_X == other.PortLocation_X &&
                PortLocation_Y == other.PortLocation_Y &&
                StorgeLocation_X == other.StorgeLocation_X &&
                StorgeLocation_Y == other.StorgeLocation_Y &&
                Type == other.Type &&
                Face == other.Face &&
                QRCode == other.QRCode &&
                isDebug == other.isDebug)
            return true;
        else
            return  false;
    }

    void SetStep(int8_t status) {
        QMutexLocker locker(&mutex); // 上锁
        StepCnt = status;
    }

    void clearStep() {
        QMutexLocker locker(&mutex); // 上锁
        StepCnt = 0;
    }
private:
    QMutex mutex; // 用于保护成员变量的互斥锁
};


class QRLocateCommand
{
public:
    static QRLocateCommand& getInstance() {
        static QRLocateCommand instance;
        return instance;
    }

    int totalLayer; //总层数
    int totalSub;   //总节数
    int portLayer;  //出货口所在层
    QList<int> subWidth;    //每小节宽度，单位mm
    int firstSubPosition;   //记录第一小节的位置，用于查找第一小节垂直架上的每层定位二维码
    int layerOffset;    //层的像素偏置，定位层的时候，二维码并不会处于图像垂直方向中间，而是有一个固定的偏执
    bool isExCompleted = true;  //动作是否完成
    int8_t StepCnt; //调试状态下步骤状态
    bool isDebug;   //是否分步调试指令

    void SetStep(int8_t status) {
        QMutexLocker locker(&mutex); // 上锁
        StepCnt = status;
    }

    void clearStep() {
        QMutexLocker locker(&mutex); // 上锁
        StepCnt = 0;
    }
private:
    QMutex mutex; // 用于保护成员变量的互斥锁
};
#endif // COMMAND_H
